home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / graphUI.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  15.3 KB  |  594 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Creation Date:  December 7/2000
  19. //  Author:         jdc rendering
  20. //
  21. // Description:
  22. //
  23. //        This file contains the procedures which implement a portable (can be
  24. //        used anywhere) user interface for viewing a shading network (with
  25. //        swatches) in a graphical layout. This file also contains the 
  26. //        procedures used to manipulate that user interface once it has been 
  27. //        created.
  28. //                                                
  29.  
  30. // ---------------------------------------------------------------------------
  31. // Special names and things like that
  32. //
  33. // "graphForm": the name of the form which contains the graph
  34. // 
  35.  
  36. // ---------------------------------------------------------------------------
  37. // Local procedures
  38. // 
  39.  
  40. global string $gGraphUILookupTable[];
  41. global int $gGraphUILookupTableCreated = false;
  42.  
  43. proc createGraphUILookupTable()
  44. {
  45.     //
  46.     // Description:
  47.     //    This procedure is called every time the user creates a graphUI
  48.     //    component, but only has any effect the first time it is called.
  49.     //    This procedure initializes the string array $gGraphUILookupTable[]
  50.     //    for use as a lookup table. The lookup table will contain information
  51.     //    about all graphUI components which exist in the current Maya
  52.     //    session.
  53.     //
  54.  
  55.     global string $gGraphUILookupTable[];
  56.     global int $gGraphUILookupTableCreated;
  57.  
  58.     if (!$gGraphUILookupTableCreated)
  59.     {
  60.         string $columns[];
  61.  
  62.         $columns[0] = "graphUI";
  63.         $columns[1] = "hypershadeName";
  64.         $columns[2] = "popupMenuScript";
  65.  
  66.         lookupTable($gGraphUILookupTable, $columns);
  67.         $gGraphUILookupTableCreated = true;
  68.     }
  69. }
  70.  
  71. proc registerGraphUI(
  72.     string $graphUI)
  73. {
  74.     //
  75.     // Description:
  76.     //    This procedure is used to register a graphUI component by entering
  77.     //    it as a row in the lookup table which contains information about all
  78.     //    graphUI components that currently exist in Maya.
  79.     //    The row created is initially blank except for the graphUI name.
  80.     //    Further information about the graphUI component must be
  81.     //    subsequently added to the lookup table.
  82.     //
  83.  
  84.     global string $gGraphUILookupTable[];
  85.     string $row[];
  86.  
  87.     $row[0] = $graphUI;
  88.     $row[1] = "";
  89.     $row[2] = "";
  90.  
  91.     lookupTableAddRow($gGraphUILookupTable, $row);
  92. }
  93.  
  94. proc registerHypershadeName(
  95.     string $graphUI,
  96.     string $hypershadeName)
  97. {
  98.     //
  99.     // Description:
  100.     //    This procedure associates the hypershadeName with the graphUI in
  101.     //    the lookup table.
  102.     //
  103.  
  104.     global string $gGraphUILookupTable[];
  105.  
  106.     // ASSUMPTION:
  107.     // We assume that a row already exists for this graphUI, as it should
  108.     // have been created by a call to registerGraphUI() as the UI was being
  109.     // created.
  110.     //
  111.     lookupTableEdit(
  112.         $gGraphUILookupTable,
  113.         "graphUI",
  114.         $graphUI,
  115.         "hypershadeName",
  116.         $hypershadeName);
  117. }
  118.  
  119. proc string lookupHypershadeName(
  120.     string $graphUI)
  121. {
  122.     //
  123.     // Description:
  124.     //    This procedure looks up the hypershade name associated with the
  125.     //    specified graphUI name in the lookup table.
  126.     //
  127.     // Returns: 
  128.     //    The hypershade name, if one is associated with the specified
  129.     //    graph UI name.
  130.     //    Otherwise: "".
  131.     //
  132.  
  133.     global string $gGraphUILookupTable[];
  134.  
  135.     return (lookupTableLookup(
  136.         $gGraphUILookupTable,
  137.         "graphUI",
  138.         $graphUI,
  139.         "hypershadeName"));
  140. }
  141.  
  142. proc string generateUniqueHypershadeName()
  143. {
  144.     //
  145.     // Description:
  146.     //    This procedure is usually called just before creating a new hypershade
  147.     //    for a graphUI.
  148.     //    This procedure generates a unique name for a hypershade by
  149.     //    creating a string of the form graph#HyperShadeEd and incrementing the #
  150.     //    part until no hypershade by that name exists.
  151.     //
  152.     // Returns: 
  153.     //    A unique name by which a hypershade can be created.
  154.     //
  155.  
  156.     int $i = 1;
  157.     while (`hyperGraph -exists ("graph" + $i + "HyperShadeEd")`)
  158.     {
  159.         $i++;
  160.     }
  161.     return ("graph" + $i + "HyperShadeEd");
  162. }
  163.     
  164. // ---------------------------------------------------------------------------
  165. // Global procedures
  166. // 
  167. global proc int graphUIIsManaged(
  168.     string $graphUI)
  169. {
  170.     //
  171.     // Description:
  172.     //    This procedure is used to query whether the overall layout of the
  173.     //    specified graphUI component is managed or not. 
  174.     //
  175.     // Returns: 
  176.     //    This procedure returns true if the overall layout is managed, false if
  177.     //    not.
  178.     //
  179.  
  180.     return `formLayout -query -manage $graphUI`;
  181. }
  182.  
  183. global proc graphUIManage(
  184.     string $graphUI,
  185.     int $manage)
  186. {
  187.     //
  188.     // Description:
  189.     //    This procedure lets the caller manage or unmanage the overall layout of
  190.     //    the specified graphUI component.
  191.     //
  192.  
  193.     formLayout -edit -manage $manage $graphUI;
  194. }
  195.  
  196. global proc string graphUIPopupMenuScript(
  197.     string $graphUI)
  198. {
  199.     //
  200.     // Description:
  201.     //    This procedure looks up the name of the popup menu script associated
  202.     //    with the specified graphUI component.
  203.     //
  204.     // Returns: 
  205.     //    The name of the popup menu script.
  206.     //
  207.  
  208.     // Lookup the name of the popup menu script in the lookup table
  209.     //
  210.     global string $gGraphUILookupTable[];
  211.  
  212.     return lookupTableLookup(
  213.         $gGraphUILookupTable,
  214.         "graphUI",
  215.         $graphUI,
  216.         "popupMenuScript");
  217. }
  218.  
  219. global proc graphUISetPopupMenuScript(
  220.     string $graphUI,
  221.     string $scriptName)
  222. {
  223.     //
  224.     // Description:
  225.     //    This procedure sets the popup menu script which is invoked when the
  226.     //    user RMB clicks in the hyperShade element of the specified graphUI
  227.     //    component. The script will be called with two arguments: the name of
  228.     //    the hyperShade editor from which the menu was invoked, and the name of
  229.     //    the popupMenu object to which the menu items are to be added.
  230.     //
  231.     //    If $scriptName is "", no popup menu will be invoked when the user RMB
  232.     //    clicks in the hyperShade editor.
  233.     //
  234.  
  235.     // Find the name of the control that the menu will be attached to
  236.     //
  237.     string $hypershadeName = lookupHypershadeName($graphUI);
  238.  
  239.     string $parent                = `hyperGraph -query -control $hypershadeName`;
  240.     string $popupMenuName        = ($hypershadeName + "PopupMenu");
  241.  
  242.     if ($scriptName == "")
  243.     {
  244.         if (`popupMenu -exists $popupMenuName`) 
  245.         {
  246.             deleteUI $popupMenuName;
  247.         }
  248.     }
  249.     else
  250.     {
  251.         // Create the popup menu
  252.         //    
  253.         if (!`popupMenu -exists $popupMenuName`) 
  254.         {
  255.             string $fullMenuName = `popupMenu -parent $parent $popupMenuName`;
  256.             popupMenu 
  257.                 -edit
  258.                 -postMenuCommand 
  259.                     ($scriptName
  260.                         + " "
  261.                         + $hypershadeName 
  262.                         + " " 
  263.                         + $popupMenuName)
  264.                 $fullMenuName;    
  265.         }
  266.     }
  267.  
  268.     // Store the name of the popup menu script in the lookup table
  269.     // 
  270.     // ASSUMPTION:
  271.     // We assume that a row already exists for this graphUI, as it should
  272.     // have been created by a call to registerGraphUI() as the UI was being
  273.     // created.
  274.     //
  275.     global string $gGraphUILookupTable[];
  276.  
  277.     lookupTableEdit(
  278.         $gGraphUILookupTable,
  279.         "graphUI",
  280.         $graphUI,
  281.         "popupMenuScript",
  282.         $scriptName);
  283. }
  284.  
  285. global proc graphUIClearGraph(
  286.     string $graphUI)
  287. {
  288.     //
  289.     // Description:
  290.     //    Calling this method causes the hyperShade editor associated with the
  291.     //    specified graphUI component to be cleared.
  292.     //
  293.  
  294.     string $hypershadeName = lookupHypershadeName($graphUI);
  295.     hyperShade -reset $hypershadeName;
  296.  
  297.     // Make this hypershade a work area so that newly created nodes will appear
  298.     // in it.
  299.     //
  300.     hyperShade 
  301.         -setWorkArea "Default" 
  302.         -dependGraphArea true 
  303.         $hypershadeName;
  304. }
  305.  
  306. global proc graphUIRearrangeGraph(
  307.     string $graphUI)
  308. {
  309.     //
  310.     // Description:
  311.     //    Calling this method causes the hyperShade editor associated with the
  312.     //    specified graphUI component to have its contents rearranged (to a
  313.     //    tidier arrangement).
  314.     //
  315.  
  316.     string $hypershadeName = lookupHypershadeName($graphUI);
  317.     hyperGraph 
  318.         -edit 
  319.         -layout 
  320.         -frameGraph
  321.         $hypershadeName;
  322. }
  323.  
  324. global proc graphUIGraphMaterials(
  325.     string $graphUI)
  326. {
  327.     //
  328.     // Description:
  329.     //    Calling this method causes the current graph in the hyperShade editor 
  330.     //    associated with the specified graphUI component to be replaced with a
  331.     //    graph of the shading network applied to the currently selected object.
  332.     //
  333.  
  334.     string $hypershadeName = lookupHypershadeName($graphUI);
  335.     hyperShade -shaderNetworks $hypershadeName;
  336.     hyperGraph -edit -frameGraph $hypershadeName;
  337. }
  338.  
  339. global proc graphUIShowUpstream(
  340.     string $graphUI)
  341. {
  342.     //
  343.     // Description:
  344.     //    Calling this method causes the current graph in the hyperShade editor 
  345.     //    associated with the specified graphUI component to be replaced with a
  346.     //    graph of the shading network upstream from the currently selected node.
  347.     //
  348.  
  349.     string $hypershadeName = lookupHypershadeName($graphUI);
  350.  
  351.     if (`optionVar -query hsClearBeforeGraphing` == 1)
  352.     {
  353.         hyperShade -clearWorkArea $hypershadeName;
  354.     }
  355.     hyperShade -networks -upStream $hypershadeName;
  356.     hyperGraph -edit -frameGraph $hypershadeName;
  357. }
  358.  
  359. global proc graphUIShowDownstream(
  360.     string $graphUI)
  361. {
  362.     //
  363.     // Description:
  364.     //    Calling this method causes the current graph in the hyperShade editor 
  365.     //    associated with the specified graphUI component to be replaced with a
  366.     //    graph of the shading network downstream from the currently selected 
  367.     //    node.
  368.     //
  369.  
  370.     string $hypershadeName = lookupHypershadeName($graphUI);
  371.  
  372.     if (`optionVar -query hsClearBeforeGraphing` == 1)
  373.     {
  374.         hyperShade -clearWorkArea $hypershadeName;
  375.     }
  376.     hyperShade -networks -downStream $hypershadeName;
  377.     hyperGraph -edit -frameGraph $hypershadeName;
  378. }
  379.  
  380. global proc graphUIShowUpAndDownstream(
  381.     string $graphUI)
  382. {
  383.     //
  384.     // Description:
  385.     //    Calling this method causes the current graph in the hyperShade editor 
  386.     //    associated with the specified graphUI component to be replaced with a
  387.     //    graph of the shading network both upstream and downstream from the 
  388.     //    currently selected node.
  389.     //
  390.  
  391.     string $hypershadeName = lookupHypershadeName($graphUI);
  392.  
  393.     if (`optionVar -query hsClearBeforeGraphing` == 1)
  394.     {
  395.         hyperShade -clearWorkArea $hypershadeName;
  396.     }
  397.     hyperShade -networks -upStream -downStream $hypershadeName;
  398.     hyperGraph -edit -frameGraph $hypershadeName;
  399. }
  400.  
  401. global proc graphUIShowPreviousGraph(
  402.     string $graphUI)
  403. {
  404.     //
  405.     // Description:
  406.     //    Each hypergraph keeps a stack of graphs in memory. Every time the user
  407.     //    graphs a network, that new graph gets pushed onto the stack.
  408.     //    Calling this method causes the current graph to be replaced with the 
  409.     //    graph which    is below the current one in the stack of graphs in memory.
  410.     //
  411.  
  412.     string $hypershadeName = lookupHypershadeName($graphUI);
  413.  
  414.     hyperGraph -edit -backward $hypershadeName;
  415. }
  416.  
  417. global proc graphUIShowNextGraph(
  418.     string $graphUI)
  419. {
  420.     //
  421.     // Description:
  422.     //    Each hypergraph keeps a stack of graphs in memory. Every time the user
  423.     //    graphs a network, that new graph gets pushed onto the stack.
  424.     //    Calling this method causes the current graph to be replaced with the 
  425.     //    graph which    is above the current one in the stack of graphs in memory.
  426.     //
  427.  
  428.     string $hypershadeName = lookupHypershadeName($graphUI);
  429.  
  430.     hyperGraph -edit -forward $hypershadeName;
  431. }
  432.  
  433. global proc graphUIAddSelected(
  434.     string $graphUI)
  435. {
  436.     //
  437.     // Description:
  438.     //    Calling this method causes the currently selected nodes to be added to
  439.     //    the contents of the hyperShade editor associated with the specified 
  440.     //     graphUI component.
  441.     //
  442.  
  443.     string $hypershadeName = lookupHypershadeName($graphUI);
  444.  
  445.     string $nodeArray[] = `ls -dependencyNodes -selection`;
  446.     int $i;
  447.  
  448.     for ($i = 0; $i < size($nodeArray); $i++)
  449.     {
  450.         hyperGraph 
  451.             -edit 
  452.             -addDependNode $nodeArray[$i] 
  453.             $hypershadeName;
  454.     }
  455. }
  456.  
  457. global proc graphUIRemoveSelected(
  458.     string $graphUI)
  459. {
  460.     //
  461.     // Description:
  462.     //    Calling this method causes the currently selected nodes to be removed
  463.     //    from the contents of the hyperShade editor associated with the 
  464.     //    specified graphUI component.
  465.     //
  466.  
  467.     string $hypershadeName = lookupHypershadeName($graphUI);
  468.  
  469.     string $nodeArray[] = `ls -dependencyNodes -selection`;
  470.     int $i;
  471.  
  472.     for ($i = 0; $i < size($nodeArray); $i++)
  473.     {
  474.         hyperGraph 
  475.             -edit 
  476.             -removeNode $nodeArray[$i] 
  477.             $hypershadeName;
  478.     }
  479. }
  480.  
  481.  
  482. global proc string graphUIHypershadeName(
  483.     string $graphUI)
  484. {
  485.     //
  486.     // Description:
  487.     //    This procedure returns the name of the hyperShade editor associated
  488.     //    with the specified graphUI component.
  489.     //
  490.  
  491.     return (lookupHypershadeName($graphUI));
  492. }
  493.  
  494. // ---------------------------------------------------------------------------
  495. // Procedures for creating and deleting a graph UI
  496. // 
  497.  
  498. global proc graphUIDelete(
  499.     string $graphUI,
  500.     int $alsoDeleteHypershade)
  501. {
  502.     if (!$alsoDeleteHypershade)
  503.     {
  504.         // The caller has asked us not to delete the hypershade object along 
  505.         // with the UI, so we unparent it from the UI before we delete the UI.
  506.         //
  507.         string $hypershadeName = lookupHypershadeName($graphUI);
  508.         hyperGraph -edit -unParent $hypershadeName;
  509.     }
  510.  
  511.     deleteUI $graphUI;
  512. }
  513.  
  514. global proc string graphUI(
  515.     string $parentFormLayout,
  516.     string $hypershadeName)
  517. {
  518.     //
  519.     // Description:
  520.     //    This procedure is called from any piece of UI which wants to create a
  521.     //    graph UI within itself. 
  522.     //    This procedure creates the graph UI.
  523.     //    If the stateDescription is specified, this code will use it to create 
  524.     //    a UI with the characteristics described therein.
  525.     //    In particular, this is designed to allow the graph UI to be moved from 
  526.     //    layout to layout without dramatically changing its appearance. 
  527.     //     Otherwise (if no stateDescription is provided), new UI is created with 
  528.     //     the default configuration.
  529.     //
  530.     // Returns: 
  531.     //    This method returns the name of the UI which should be stored by the
  532.     //    caller for later use in performing operations on the graph UI.
  533.     //
  534.  
  535.     // Create the lookup table if it does not already exist.
  536.     //
  537.     createGraphUILookupTable();
  538.  
  539.     int $newHypershadeCreated = false;
  540.  
  541.     if ($hypershadeName == "")
  542.     {
  543.         $hypershadeName = generateUniqueHypershadeName();
  544.         hyperGraph -unParent $hypershadeName;
  545.         hyperUserInit($hypershadeName);
  546.         $newHypershadeCreated = true;
  547.     }
  548.  
  549.     string $graphUI;
  550.  
  551.     int $iconSize = 26;
  552.  
  553.     $graphUI = `formLayout graph`;
  554.         // Register the graphUI in the lookup table
  555.         //
  556.         registerGraphUI($graphUI);
  557.         registerHypershadeName($graphUI, $hypershadeName);
  558.  
  559.         hyperGraph 
  560.             -edit
  561.             -parent $graphUI
  562.             $hypershadeName;
  563.  
  564.         formLayout
  565.             -edit
  566.             -af $hypershadeName top 0
  567.             -af $hypershadeName bottom 0
  568.             -af $hypershadeName left 0
  569.             -af $hypershadeName right 0
  570.             $graphUI;
  571.     setParent ..; // from $graphUI
  572.     formLayout 
  573.         -edit
  574.         -af $graphUI top         0
  575.         -af $graphUI bottom     0
  576.         -af $graphUI left         0
  577.         -af $graphUI right         0
  578.         $parentFormLayout;
  579.  
  580.     if ($newHypershadeCreated)
  581.     {
  582.         // Make this hypershade a work area so that newly created nodes will 
  583.         // appear in it.
  584.         //
  585.         hyperShade 
  586.             -setWorkArea "Default" 
  587.             -dependGraphArea true 
  588.             $hypershadeName;
  589.     }
  590.  
  591.     return $graphUI;
  592. }
  593.  
  594.